<html>
    <head>
        <script type="text/javascript" src="..\Core\jquery-1.2.6.js"></script>
        <script type="text/javascript" src="..\Core\jstest.js"></script>

        <style type="text/css">
            .fixture_list { }
            .fixture { list-style-type: none; }            
            .test_list { list-style-type:none; }
            .failed_test { color:Red; }            
            .passed_test { }
        </style>        
    </head>
    <body>
        <h4>Output builder tests</h4>
        
        <div id="outputDiv" style="font-family:Verdana; font-size:10pt; border:1px solid gray">
        </div>
        
        <script type="text/javascript">
            $(document).ready( function() {

            function assert(expr, msg) {
                if (expr)
                    console.log("ok: " + assert.caller.name);
                else
                    console.error("FAILED: " + assert.caller.name);
            }


            function assertEqual(expected, actual) {
                if (expected === actual)
                    console.log("ok: " + assertEqual.caller.name);
                else
                    console.error("FAILED: " + assertEqual.caller.name + " -> expected: " + expected + ", actual: " + actual);
            }

            function createSuite() {
                return new SpecSuite().FindContextsStartingWith("context");
            }

            
            (function new_tests_are_pushed_to_current_fixture() {
                var handler = new SpecOutput();
                                
                handler.beginLoggingFixture("first name");                
                                
                handler.logFailedTest("failed test 1", "message1");
                handler.logPassedTest("failed test 2");
                handler.logFailedTest("failed test 3", "message3");
                handler.logPassedTest("failed test 4");
                
                assertEqual(4, handler.currentFixture.tests.length)
            })();
            
            (function adding_tests_to_second_fixture_does_not_add_tests_to_first() {
                var handler = new SpecOutput();
                                
                handler.beginLoggingFixture("first name");                                                
                handler.logFailedTest("failed test 1", "message1");
                handler.logPassedTest("passed test 2");
                
                handler.beginLoggingFixture("another fixture");
                handler.logPassedTest("passed test 3");
                handler.logPassedTest("passed test 4");
                handler.logPassedTest("passed test 5");
                
                assertEqual(2, handler.fixtureResults.length);
                assertEqual(3, handler.currentFixture.tests.length);
            })();


            (function renders_output_to_specified_html_element() {            
                var handler = new SpecOutput();
                                
                handler.beginLoggingFixture("first fixture");                
                                
                handler.logFailedTest("failed test 1", "message1");
                handler.logPassedTest("passed test 2");
                handler.logFailedTest("failed test 3", "message3");
                handler.logPassedTest("passed test 4");
                                
                handler.renderOutput("outputDiv");                
                                
                assert($("#outputDiv").children("ul").length > 0);
            })();

            });
            
            
            /*
            TODO:
            - various output validation (simplistic tree form)            
                - renders empty fixture with css class of "empty_fixture"
                - renders fixture with failed tests with css class "failed_fixture"
                - renders fixture with passed tests with css class "passed_fixture"
                - should render fixtures in UL element, with test names as LI's
            */
        
        </script>
    </body>
</html>


